/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function(nums) {
    let n=nums.length-1
    let major=nums[n]
    let vote=1
    for(let i=0;i<n;i++){
        if(vote===0){
            major=nums[i]
        }
        vote += nums[i] === major ? 1 : -1;
    }
    return major
};

let nums = [2,2,1,1,1,2,2]
console.log(majorityElement(nums));